package com.example.uwe;

import com.example.uwe.service.AccommodationService;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

public class  UWEAccommodationSystem extends Application {
    private static AccommodationService accommodationService;
    
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(UWEAccommodationSystem.class.getResource("accommodation-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 800, 600);
        
        AccommodationController controller = fxmlLoader.getController();
        controller.setAccommodationService(accommodationService);
        
        stage.setTitle("UWE Accommodation System");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        try {
            Connection connection = DatabaseConnection.getConnection();
            accommodationService = new AccommodationService();
            launch();
        } catch (SQLException e) {
            System.err.println("数据库连接失败: " + e.getMessage());
            System.exit(1);
        }
    }
}